package com._9xcloud.leaverequest.service;

import com._9xcloud.leaverequest.domain.Subject;
import com._9xcloud.leaverequest.repository.SubjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2015/5/28.
 */
@Repository
@Transactional
public class SubjectServiceImpl implements SubjectService {
    @Autowired
    private SubjectRepository subjectRepository;

    public Subject create(String subjectName) {
        Subject subject = new Subject(subjectName);
        return subjectRepository.saveAndFlush(subject);
    }

    @Transactional(readOnly = true)
    public List<Subject> getAll() {
        return subjectRepository.findAll();
    }

    public void removeAll() {
        subjectRepository.deleteAll();
        subjectRepository.flush();
    }

}
